package com.study.suanfa.paixu;

import java.util.Arrays;

/**
 * @description: maopao   冒泡排序
 * @date: 2020/11/24 20:56
 * @author: hcm
 * @version: 1.0
 */
public class maopao {

    public static void main(String[] args) {

        int[] arr = {3,5,61,8,1};
        bubbleSort(arr);

    }



    /**
     * 冒泡排序
     */
    private static void bubbleSort(int[] arr) {

        //遍历
        for (int i = 0; i < arr.length - 1 ; i++) {
            for (int j = 0; j < arr.length - i - 1; j++) {

                //置换辅助对象
                int temp = arr[j+1];
                //置换条件
                if(arr[j] >arr[j+1]){
                    arr[j + 1] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }
}
